{% extends "base.html" %}

{% block title %}线索管理 - {% if lead %}编辑线索{% else %}添加线索{% endif %}{% endblock %}

{% block page_title %}{% endblock %}
{% block page_subtitle %}{% endblock %}

{% block content %}
<div class="container mx-auto space-y-6">
    <!-- 面包屑导航 -->
    <nav class="text-sm breadcrumbs mb-6">
        <ol class="flex items-center space-x-2">
            <li><a href="{{ url_for('main.home') }}" class="text-gray-500 hover:text-gray-700">首页</a></li>
            <li><i class="fas fa-chevron-right text-gray-400 text-xs mx-2"></i></li>
            <li><a href="{{ url_for('lead.lead_list') }}" class="text-gray-500 hover:text-gray-700">线索管理</a></li>
            <li><i class="fas fa-chevron-right text-gray-400 text-xs mx-2"></i></li>
            <li class="text-gray-700">{% if lead %}编辑线索{% else %}添加线索{% endif %}</li>
        </ol>
    </nav>

    <div class="bg-white rounded-lg shadow">
        <div class="p-6">
            <form method="post">
                <input type="hidden" name="csrf_token" value="{{ csrf_token() }}">
                <div class="grid grid-cols-1 gap-6">
                    <!-- 基本信息 -->
                    <div>
                        <h3 class="text-lg font-medium text-gray-900 mb-4">基本信息</h3>
                        <div class="grid grid-cols-1 md:grid-cols-2 gap-6">
                            <div>
                                <label for="name" class="block text-sm font-medium text-gray-700">线索名称 <span class="text-red-500">*</span></label>
                                <input type="text" name="name" id="name" required
                                    class="mt-1 block w-full border border-gray-300 rounded-md shadow-sm py-2 px-3 focus:outline-none focus:ring-primary focus:border-primary"
                                    value="{{ lead.name if lead else '' }}">
                            </div>
                            <div>
                                <label for="company" class="block text-sm font-medium text-gray-700">公司名称 <span class="text-red-500">*</span></label>
                                <input type="text" name="company" id="company" required
                                    class="mt-1 block w-full border border-gray-300 rounded-md shadow-sm py-2 px-3 focus:outline-none focus:ring-primary focus:border-primary"
                                    value="{{ lead.company if lead else '' }}">
                            </div>
                            <div>
                                <label for="source" class="block text-sm font-medium text-gray-700">线索来源 <span class="text-red-500">*</span></label>
                                <select name="source" id="source" required
                                    class="mt-1 block w-full border border-gray-300 rounded-md shadow-sm py-2 px-3 focus:outline-none focus:ring-primary focus:border-primary">
                                    <option value="">请选择线索来源</option>
                                    <option value="官网" {% if lead and lead.source == '官网' %}selected{% endif %}>官网</option>
                                    <option value="推荐" {% if lead and lead.source == '推荐' %}selected{% endif %}>推荐</option>
                                    <option value="展会" {% if lead and lead.source == '展会' %}selected{% endif %}>展会</option>
                                    <option value="广告" {% if lead and lead.source == '广告' %}selected{% endif %}>广告</option>
                                    <option value="电话咨询" {% if lead and lead.source == '电话咨询' %}selected{% endif %}>电话咨询</option>
                                    <option value="社交媒体" {% if lead and lead.source == '社交媒体' %}selected{% endif %}>社交媒体</option>
                                    <option value="其他" {% if lead and lead.source == '其他' %}selected{% endif %}>其他</option>
                                </select>
                            </div>
                            <div>
                                <label for="status" class="block text-sm font-medium text-gray-700">线索状态 <span class="text-red-500">*</span></label>
                                <select name="status" id="status" required
                                    class="mt-1 block w-full border border-gray-300 rounded-md shadow-sm py-2 px-3 focus:outline-none focus:ring-primary focus:border-primary">
                                    <option value="">请选择线索状态</option>
                                    <option value="新线索" {% if lead and lead.status == '新线索' %}selected{% endif %}>新线索</option>
                                    <option value="跟进中" {% if lead and lead.status == '跟进中' %}selected{% endif %}>跟进中</option>
                                    <option value="已转化" {% if lead and lead.status == '已转化' %}selected{% endif %}>已转化</option>
                                    <option value="已关闭" {% if lead and lead.status == '已关闭' %}selected{% endif %}>已关闭</option>
                                </select>
                            </div>
                            <div>
                                <label for="priority" class="block text-sm font-medium text-gray-700">优先级 <span class="text-red-500">*</span></label>
                                <select name="priority" id="priority" required
                                    class="mt-1 block w-full border border-gray-300 rounded-md shadow-sm py-2 px-3 focus:outline-none focus:ring-primary focus:border-primary">
                                    <option value="">请选择优先级</option>
                                    <option value="高" {% if lead and lead.priority == '高' %}selected{% endif %}>高</option>
                                    <option value="中" {% if lead and lead.priority == '中' %}selected{% endif %}>中</option>
                                    <option value="低" {% if lead and lead.priority == '低' %}selected{% endif %}>低</option>
                                </select>
                            </div>
                            <div>
                                <label for="manager_id" class="block text-sm font-medium text-gray-700">负责人</label>
                                <select name="manager_id" id="manager_id"
                                    class="mt-1 block w-full border border-gray-300 rounded-md shadow-sm py-2 px-3 focus:outline-none focus:ring-primary focus:border-primary">
                                    <option value="">请选择负责人</option>
                                    {% for user in users %}
                                    <option value="{{ user.id }}" {% if lead and lead.manager_id == user.id %}selected{% endif %}>{{ user.name }}</option>
                                    {% endfor %}
                                </select>
                            </div>
                            <div>
                                <label for="expected_amount" class="block text-sm font-medium text-gray-700">预期金额（元）</label>
                                <input type="number" name="expected_amount" id="expected_amount" min="0" step="0.01"
                                    class="mt-1 block w-full border border-gray-300 rounded-md shadow-sm py-2 px-3 focus:outline-none focus:ring-primary focus:border-primary"
                                    value="{{ lead.expected_amount if lead else '' }}">
                            </div>
                            <div>
                                <label for="expected_close_date" class="block text-sm font-medium text-gray-700">预期成交日期</label>
                                <input type="date" name="expected_close_date" id="expected_close_date"
                                    class="mt-1 block w-full border border-gray-300 rounded-md shadow-sm py-2 px-3 focus:outline-none focus:ring-primary focus:border-primary"
                                    value="{{ lead.expected_close_date if lead else '' }}">
                            </div>
                        </div>
                    </div>

                    <!-- 联系信息 -->
                    <div>
                        <h3 class="text-lg font-medium text-gray-900 mb-4">联系信息</h3>
                        <div class="grid grid-cols-1 md:grid-cols-2 gap-6">
                            <div>
                                <label for="phone" class="block text-sm font-medium text-gray-700">联系电话 <span class="text-red-500">*</span></label>
                                <input type="text" name="phone" id="phone" required
                                    class="mt-1 block w-full border border-gray-300 rounded-md shadow-sm py-2 px-3 focus:outline-none focus:ring-primary focus:border-primary"
                                    value="{{ lead.phone if lead else '' }}">
                            </div>
                            <div>
                                <label for="email" class="block text-sm font-medium text-gray-700">电子邮箱</label>
                                <input type="email" name="email" id="email"
                                    class="mt-1 block w-full border border-gray-300 rounded-md shadow-sm py-2 px-3 focus:outline-none focus:ring-primary focus:border-primary"
                                    value="{{ lead.email if lead else '' }}">
                            </div>
                            <div>
                                <label for="position" class="block text-sm font-medium text-gray-700">职位</label>
                                <input type="text" name="position" id="position"
                                    class="mt-1 block w-full border border-gray-300 rounded-md shadow-sm py-2 px-3 focus:outline-none focus:ring-primary focus:border-primary"
                                    value="{{ lead.position if lead else '' }}">
                            </div>
                            <div>
                                <label for="department" class="block text-sm font-medium text-gray-700">部门</label>
                                <input type="text" name="department" id="department"
                                    class="mt-1 block w-full border border-gray-300 rounded-md shadow-sm py-2 px-3 focus:outline-none focus:ring-primary focus:border-primary"
                                    value="{{ lead.department if lead else '' }}">
                            </div>
                            <div class="md:col-span-2">
                                <label for="address" class="block text-sm font-medium text-gray-700">公司地址</label>
                                <input type="text" name="address" id="address"
                                    class="mt-1 block w-full border border-gray-300 rounded-md shadow-sm py-2 px-3 focus:outline-none focus:ring-primary focus:border-primary"
                                    value="{{ lead.address if lead else '' }}">
                            </div>
                        </div>
                    </div>

                    <!-- 需求信息 -->
                    <div>
                        <h3 class="text-lg font-medium text-gray-900 mb-4">需求信息</h3>
                        <div>
                            <label for="requirements" class="block text-sm font-medium text-gray-700">需求描述</label>
                            <textarea name="requirements" id="requirements" rows="4"
                                class="mt-1 block w-full border border-gray-300 rounded-md shadow-sm py-2 px-3 focus:outline-none focus:ring-primary focus:border-primary">{{ lead.requirements if lead else '' }}</textarea>
                        </div>
                    </div>

                    <!-- 备注信息 -->
                    <div>
                        <h3 class="text-lg font-medium text-gray-900 mb-4">备注信息</h3>
                        <div>
                            <label for="remarks" class="block text-sm font-medium text-gray-700">备注</label>
                            <textarea name="remarks" id="remarks" rows="4"
                                class="mt-1 block w-full border border-gray-300 rounded-md shadow-sm py-2 px-3 focus:outline-none focus:ring-primary focus:border-primary">{{ lead.remarks if lead else '' }}</textarea>
                        </div>
                    </div>
                </div>

                <div class="mt-6 flex justify-end space-x-3">
                    <a href="{{ url_for('lead.lead_list') }}" class="px-4 py-2 border border-gray-300 rounded-md shadow-sm text-sm font-medium text-gray-700 bg-white hover:bg-gray-50 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-primary">
                        取消
                    </a>
                    <button type="submit" class="px-4 py-2 border border-transparent rounded-md shadow-sm text-sm font-medium text-white bg-primary hover:bg-blue-600 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-primary">
                        {% if lead %}保存修改{% else %}添加线索{% endif %}
                    </button>
                </div>
            </form>
        </div>
    </div>
</div>
{% endblock %}